﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>TableTwoReport</title>
    <link id="easyuiTheme" href="/Res/easyui/themes/metro/easyui.css" rel="stylesheet" type="text/css" />
    <link href="/Content/default.css" rel="stylesheet" />

    <script src="/Scripts/jquery-1.8.3.min.js"></script>
    <script src="/Res/easyui/jquery.easyui.min.js"></script>
    <script src="/Res/easyui/jquery.cookie.js"></script>
    <script src="/Res/easyui/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript">
        $(function () {
            $('#hProjectID').val("<%=Request.Params["ProjectID"]%>");
            $('#hContractType').val("<%=Request.Params["ContractType"]%>");
            $('#hContractID').val("<%=Request.Params["ContractID"]%>");
            $('#hContractStagesID').val("<%=Request.Params["ContractStagesID"]%>");
            $('#ContractType').combobox({
                editable: false, panelHeight: "auto",
                valueField: "DictionaryName",
                textField: "DictionaryName",
                url: "/Dictionary/GetDictionaryByTypeTag?typeTag=ContractType",
                onLoadSuccess: function () {
                    var data = $('#ContractType').combobox('getData');
                    if (data.length > 0) {
                        if ($('#hContractType').val() != '') {
                            $('#ContractType').combobox('select', ($('#hContractType').val()));
                        }
                        else {
                            $('#ContractType').combobox('select', data[0]["DictionaryName"]);
                        }

                        $("#ProjectID").combobox({
                            editable: false, panelHeight: "auto",
                            valueField: 'ID',
                            textField: 'ProjectName',
                            url: '/ProjectInfo/ProjectInfoListForFlow',
                            onLoadSuccess: function () {
                                var data = $("#ProjectID").combobox('getData');
                                if (data.length > 0) {
                                    if ($('#hProjectID').val() != '') {
                                        $('#ProjectID').combobox('select', ($('#hProjectID').val()));
                                    }
                                    else {
                                        $('#ProjectID').combobox('select', data[0]["ID"]);
                                    }
                                }
                            },
                            onSelect: function (record) {
                                var contractType = $("#ContractType").combobox('getValue');
                                initContract(record.ID, contractType);
                            }
                        });
                    }
                },
                onSelect: function (record) {
                    var projectID = $("#ProjectID").combobox('getValue');
                    if (projectID != '') {
                        initContract(projectID, record.DictionaryName);
                    }
                }
            });
        });

        function initContract(projectID, contractType) {
            $("#ContractID").combobox({
                editable: false, panelHeight: "auto",
                valueField: 'ID',
                textField: 'ContractName',
                url: '/ContractInfo/ContractInfoListByProjectIDAndType?projectID=' + projectID + '&contractType=' + encodeURI(contractType),
                onLoadSuccess: function () {
                    var data = $("#ContractID").combobox('getData');
                    if (data.length > 0) {
                        if ($('#hContractID').val() != '') {
                            $('#ContractID').combobox('select', ($('#hContractID').val()));
                        }
                        else {
                            $('#ContractID').combobox('select', data[0]["ID"]);
                        }
                    }
                    else {
                        initExpense('', '');
                    }
                },
                onSelect: function (record) {
                    var projectID = $("#ProjectID").combobox('getValue');
                    if (projectID != '') {
                        initExpense(projectID, record.ID);
                    }
                }
            });
        }

        function initExpense(projectID, contractID) {
            $("#ContractStagesID").combobox({
                editable: false, panelHeight: "auto",
                valueField: 'ContractStages',
                textField: 'ContractStagesStr',
                url: '/Expense/GetExpenseByProjectIDAndContractID?projectID=' + projectID + '&contractID=' + contractID,
                onLoadSuccess: function () {
                    var data = $("#ContractStagesID").combobox('getData');
                    if (data.length > 0) {
                        if ($('#hContractStagesID').val() != '') {
                            $('#ContractStagesID').combobox('select', ($('#hContractStagesID').val()));
                        }
                        else {
                            $('#ContractStagesID').combobox('select', data[0]["ContractStages"]);
                        }
                    }
                }
            });
        }
    </script>

    <script runat="server">
        void Page_Load(object sender, EventArgs e)
        {
            if (ViewData["TableTwoReportChartView"] != null)
            {
                ReportViewer1.LocalReport.ReportPath = @"bin\Report\TableTwoReport.rdlc";
                ReportViewer1.LocalReport.DataSources.Clear();

                List<Bricks.Site.Models.TableTwoReportTitleView> lstTableTwoReportTitleView = ViewData["TableTwoReportTitleView"] as List<Bricks.Site.Models.TableTwoReportTitleView>;                
                ReportDataSource source = new ReportDataSource();
                source.Name = "TableTwoReportTitleView";
                source.Value = lstTableTwoReportTitleView;
                ReportViewer1.LocalReport.DataSources.Add(source); 
                
                List<Bricks.Site.Models.TableTwoReportChartView> lstTableTwoReportChartView = ViewData["TableTwoReportChartView"] as List<Bricks.Site.Models.TableTwoReportChartView>;                
                ReportDataSource source1 = new ReportDataSource();
                source1.Name = "TableTwoReportChartView";
                source1.Value = lstTableTwoReportChartView;
                ReportViewer1.LocalReport.DataSources.Add(source1); 
                
                List<Bricks.Site.Models.DBViewModel.Expense.VMExpenseSecond> lstVMExpenseSecond = ViewData["TableTwoReportTableView"] as List<Bricks.Site.Models.DBViewModel.Expense.VMExpenseSecond>;
                ReportDataSource source2 = new ReportDataSource();
                source2.Name = "TableTwoReportTableView";
                source2.Value = lstVMExpenseSecond;
                ReportViewer1.LocalReport.DataSources.Add(source2); 
                
                ReportViewer1.ZoomMode = ZoomMode.PageWidth;
                ReportViewer1.LocalReport.Refresh();
            }
        }
    </script>
</head>
<body>
    <form id="frmStageReport" runat="server">
        <div>
            <input type="hidden" id="hProjectID" />
            <input type="hidden" id="hContractType" />
            <input type="hidden" id="hContractID" />
            <input type="hidden" id="hContractStagesID" />
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            <%using (Html.BeginForm("TableTwoReport", "Report"))
              {%>
            <table style="margin-top: 5px">
                <tr>
                    <td style="width: 95px; text-align: center">项目名称</td>
                    <td>
                        <input id="ProjectID" name="ProjectID" class="easyui-combobox" style="width: 360px;" />
                    </td>
                    <td style="width: 95px; text-align: center">合同类型</td>
                    <td>
                        <input id="ContractType" name="ContractType" class="easyui-combobox" style="width: 360px;" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 95px; text-align: center">标段名称</td>
                    <td>
                        <input id="ContractID" name="ContractID" class="easyui-combobox" style="width: 360px;" />
                    </td>
                    <td style="width: 95px; text-align: center">期次</td>
                    <td>
                        <input id="ContractStagesID" name="ContractStagesID" class="easyui-combobox" style="width: 200px;" />
                        <input type="submit" value="预览" />
                    </td>
                </tr>
            </table>
            <%}
            %>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="false" Font-Names="Verdana" Font-Size="8pt" BackColor="#eaf6fc" Width="100%" Height="920px" ShowFindControls="false" ShowPrintButton="true">
            </rsweb:ReportViewer>
        </div>
    </form>
</body>
</html>
